import java.io.Serializable;
import java.rmi.RemoteException;

import net.jini.core.event.RemoteEvent;
import net.jini.core.event.RemoteEventListener;
import net.jini.core.event.UnknownEventException;
import net.jini.export.Exporter;

import net.jini.jeri.BasicILFactory;
import net.jini.jeri.BasicJeriExporter;
import net.jini.jeri.tcp.TcpServerEndpoint;

public class JavaSpaceListener implements RemoteEventListener, Serializable {
	private int fNot;

	private RemoteEventListener theStub;

	public JavaSpaceListener() throws RemoteException {
		fNot = 0;
		Exporter myDefaultExporter = new BasicJeriExporter(TcpServerEndpoint.getInstance(0), new BasicILFactory(), false, true);

		theStub = (RemoteEventListener) myDefaultExporter.export(this);
	}

	public RemoteEventListener getStub() {
		return theStub;
	}

	public void notify(RemoteEvent arg0) throws UnknownEventException, RemoteException {
		System.out.println("Notified");
		fNot++;
	}

	public void decreaseNotifications() {
		fNot--;
	}

	public boolean isNotified() {
		return fNot > 0;
	}

	public void resetNotifications() {
		fNot = 0;
	}
}
